<!DOCTYPE html>
<!--
     SPDX-License-Identifier: CC-BY-SA-4.0
     SPDX-FileCopyrightText: 2020 seL4 Project a Series of LF Projects, LLC.
-->
<!-- Page last generated 2025-02-20 03:16:15 +0000 -->
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Rocketchip FPGA mapped to Zynq ZCU102 | seL4 docs</title>

    <!-- Our stylesheet and theme stylesheet.  Contains bootstrap. -->
    <link rel="stylesheet" href="/assets/css/style.css" type="text/css">
    <!-- Font awesome -->
    <link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <!-- Pygments syntax highlighting  -->
    <link rel="stylesheet" href="/assets/css/highlighting/trac.css" type="text/css">
    <link rel="icon" type="image/x-icon" href="/assets/favicon.ico"><script defer data-domain="docs.sel4.systems"
	    src="https://analytics.sel4.systems/js/script.js"></script></head>

  <body class="container-fluid">

    



<header>
  <ul class="row menu">
    <li class="col-xs-12 col-md-2" >
            <a href="https://sel4.systems" class="skip-icon">
              <img class="img-responsive" src="/assets/logo-text-white.svg" alt="seL4 logo" />
            </a>
    </li>
    <li class="col-xs-12 col-md-10 menu">
      <nav aria-label="Banner links">
        <h2><a href="/Resources" />Resources</h2>
        <h2><a href="/processes" />Contributing</a></h2>
        <h2><a href="/projects" />Projects</h2>
        <h2><a href="/Tutorials" />Tutorials</h2>
        <iframe title="DuckDuckGo search bar" src="https://duckduckgo.com/search.html?site=docs.sel4.systems&prefill=Search%20sel4.systems" style="overflow:hidden;margin-bottom:10px; padding:0;height:40px;float:right;border-width: 0px"></iframe>
      </nav>
    </li>
  </ul>
  <div class="clear"></div>
  
<div class="breadcrumbs bootstrap hidden-sm-down">
  <nav class="sel-breadcrumb" aria-label="Breadcrumb" >
    <ol class=" list-unstyled" vocab="http://schema.org/" typeof="BreadcrumbList">
      
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/">
              <span property="name"><b>seL4 Docs</b></span>
            </a>
            <meta property="position" content="1" />
        </li>
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/Hardware/">
              <span property="name"><b>Supported platforms</b></span>
            </a>
            <meta property="position" content="2" />
        </li>
      
        

        
          <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <span property="name">Rocketchip FPGA mapped to Zynq ZCU102</span>
            <meta property="position" content="3" /></li>
          
    </ol>
  </nav>
  <nav class="sel-version" aria-label="Current Versions">
    <ol class="list-unstyled">
      <li class="list-unstyled text-right" style="margin-left:auto; padding:0rem 0rem;">
        Current versions:</li>
      <li class="list-unstyled text-right">
      <a href="/releases/sel4/13.0.0"><b>seL4-13.0.0</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/microkit/1.4.1"><b>microkit-1.4.1</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/camkes/camkes-3.11.0"><b>camkes-3.11.0</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/capdl/0.3.0"><b>capDL-0.3.0</b></a></li>
      </ol>
  </nav>
  <div class='clear'></div>
</div>


</header>

    <main>
      <div class="row">
  <div class="hidden-xs col-sm-4 col-md-3 col-lg-2">
    


<div class="sidebar">
















</div>

  </div>
  <div class="col-sm-8 col-md-9 col-lg-8 main">
    
    <div class="content">
      <h1 id="rocketchip-fpga-mapped-to-zynq-zcu102">Rocketchip FPGA mapped to Zynq ZCU102</h1>

<p>This rocketchip implementation will run on the ZCU102 FPGA fabric.</p>

<h2 id="building-the-gcc-toolchain">Building the GCC toolchain</h2>

<ol>
  <li>
    <p>It is recommended to build the toolchain from source.</p>

    <div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code> git clone https://github.com/riscv/riscv-gnu-toolchain.git
 <span class="nb">cd </span>riscv-gnu-toolchain
 git submodule update <span class="nt">--init</span> <span class="nt">--recursive</span>
 <span class="nb">export </span><span class="nv">RISCV</span><span class="o">=</span>/opt/riscv
 ./configure <span class="nt">--prefix</span><span class="o">=</span><span class="s2">"</span><span class="k">${</span><span class="nv">RISCV</span><span class="k">}</span><span class="s2">"</span> <span class="nt">--enable-multilib</span>
 make linux
</code></pre></div>    </div>

    <p>After it is built, add the <code class="language-plaintext highlighter-rouge">$RISCV/bin</code> folder to your PATH. The built
 toolchain works for both 32-bit and 64-bit.</p>
  </li>
  <li>
    <p>Alternatively, any pre-built toolchain with multilib enabled should work.</p>
  </li>
</ol>

<h2 id="building-sel4test">Building seL4test</h2>

<p>Checkout the sel4test project using repo as per <a href="/seL4Test">seL4Test</a></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>repo init <span class="nt">-u</span> https://github.com/seL4/sel4test-manifest.git
repo <span class="nb">sync
mkdir </span>cbuild
<span class="nb">cd </span>cbuild
../init-build.sh <span class="nt">-DPLATFORM</span><span class="o">=</span>rocketchip-zcu102 <span class="nt">-DRISCV64</span><span class="o">=</span>1
<span class="c"># The default cmake wrapper sets up a default configuration for the target platform.</span>
<span class="c"># To change individual settings, run `ccmake` and change the configuration</span>
<span class="c"># parameters to suit your needs.</span>
ninja

</code></pre></div></div>

<p>Generated binaries can be found in the <code class="language-plaintext highlighter-rouge">images/</code> directory.</p>

<h3 id="updating-opensbi">Updating OpenSBI</h3>

<p>In order to run on the ZCU102, the OpenSBI platform must be changed from <code class="language-plaintext highlighter-rouge">generic</code>.
<a href="https://github.com/dornerworks/opensbi/tree/bao/rocket">DornerWorks</a> has forked a version of
OpenSBI from the bao-project that supports the ZCU104 platform, which is nearly identical to the
ZCU102. Perform the following commands in the seL4 codebase to set the OpenSBI target to
<code class="language-plaintext highlighter-rouge">rocket-fpga-zcu104</code>.</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd </span>tools/opensbi
git remote add dornerworks https://github.com/dornerworks/opensbi/
git fetch dornerworks
git checkout dornerworks/bao/rocket
</code></pre></div></div>

<h2 id="building-the-rocketchip-bitstream">Building the Rocketchip Bitstream</h2>

<h3 id="setting-up-the-repo">Setting up the Repo</h3>

<p>The following repository contains patches that will add virtualization support via the h-extensions
to the rocketchip. Clone the repo with the following command</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/dornerworks/Vivado-Prebuilts
git clone https://github.com/dornerworks/bao-demos <span class="nt">-b</span> rocket rocketchip-h-extend
<span class="nb">cd </span>rocketchip-h-extend
</code></pre></div></div>

<p>Export the following variables for the scripts to work correctly. Please note that order is also
important since some of these variables use previous variables in their declaration.</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">PLATFORM</span><span class="o">=</span>rocket-fpga-zcu104
<span class="nb">export </span><span class="nv">DW_VIVADO_PREBUILTS</span><span class="o">=</span>/PATH/TO/vivado-prebuilts
<span class="nb">export </span><span class="nv">BAO_DEMOS</span><span class="o">=</span>/PATH/TO/rocketchip-h-extend
<span class="nb">export </span><span class="nv">BAO_DEMOS_WRKDIR</span><span class="o">=</span><span class="nv">$BAO_DEMOS</span>/wrkdir
<span class="nb">export </span><span class="nv">BAO_DEMOS_WRKDIR_SRC</span><span class="o">=</span><span class="nv">$BAO_DEMOS_WRKDIR</span>/srcs
<span class="nb">export </span><span class="nv">BAO_DEMOS_WRKDIR_PLAT</span><span class="o">=</span><span class="nv">$BAO_DEMOS_WRKDIR</span>/imgs/<span class="nv">$PLATFORM</span>
<span class="nb">export </span><span class="nv">BAO_DEMOS_CHIPYARD</span><span class="o">=</span><span class="nv">$BAO_DEMOS_WRKDIR_SRC</span>/chipyard
<span class="nb">export </span><span class="nv">BAO_DEMOS_ROCKETCHIP</span><span class="o">=</span><span class="nv">$BAO_DEMOS_CHIPYARD</span>/generators/rocket-chip
<span class="nb">export </span><span class="nv">BAO_DEMOS_VIVADO_SCRIPTS</span><span class="o">=</span><span class="nv">$BAO_DEMOS</span>/platforms/<span class="nv">$PLATFORM</span>/scripts
<span class="nb">export </span><span class="nv">BAO_DEMOS_ROCKET_CONFIG</span><span class="o">=</span>RocketHypConfig<span class="si">$(</span><span class="nb">echo</span> <span class="nv">$PLATFORM</span> | <span class="nb">awk</span> <span class="s1">'{split($0,A,"-"); print A[length(A)]}'</span><span class="si">)</span>
<span class="nb">export </span><span class="nv">BAO_DEMOS_OPENSBI</span><span class="o">=</span><span class="nv">$BAO_DEMOS_WRKDIR_SRC</span>/opensbi
<span class="nb">export </span><span class="nv">ARCH</span><span class="o">=</span>riscv
<span class="nb">export </span><span class="nv">CROSS_COMPILE</span><span class="o">=</span>riscv64-unknown-elf-
<span class="nb">export </span><span class="nv">VIVADO_CORES</span><span class="o">=</span><span class="si">$(</span><span class="nb">nproc</span><span class="si">)</span>

<span class="nb">mkdir</span> <span class="nt">-p</span> <span class="nv">$BAO_DEMOS_WRKDIR</span>
<span class="nb">mkdir</span> <span class="nt">-p</span> <span class="nv">$BAO_DEMOS_WRKDIR_SRC</span>
</code></pre></div></div>

<h3 id="generate-the-soc-design">Generate the SoC Design</h3>

<p>With these variables in place use the following commands to generate the rocketchip design with the
h-extensions enabled:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/ucb-bar/chipyard.git <span class="nv">$BAO_DEMOS_CHIPYARD</span>
<span class="nb">cd</span> <span class="nv">$BAO_DEMOS_CHIPYARD</span>
git checkout 64632c8
./scripts/init-submodules-no-riscv-tools.sh
git apply <span class="nv">$BAO_DEMOS</span>/platforms/<span class="nv">$PLATFORM</span>/patches/0001-add-rocket-hyp-fpga-support.patch
git <span class="nt">-C</span> generators/boom apply <span class="nv">$BAO_DEMOS</span>/platforms/<span class="nv">$PLATFORM</span>/patches/0001-boom-add-usehyp-option.patch
git <span class="nt">-C</span> generators/ariane apply <span class="nv">$BAO_DEMOS</span>/platforms/<span class="nv">$PLATFORM</span>/patches/0001-ariane-add-usehyp-option.patch
<span class="nb">cd</span> <span class="nv">$BAO_DEMOS_ROCKETCHIP</span>
git remote add hyp https://github.com/dornerworks/rocket-chip.git
git fetch hyp
git checkout hyp
</code></pre></div></div>

<p>Next use the following command to build the bootROM:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>make <span class="nt">-C</span> <span class="nv">$BAO_DEMOS_CHIPYARD</span>/bootromFPGA
</code></pre></div></div>

<p>Finally, use the following command to generate the verilog before building the design:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>make <span class="nt">-C</span> <span class="nv">$BAO_DEMOS_CHIPYARD</span>/sims/vcs verilog <span class="nv">SUB_PROJECT</span><span class="o">=</span>rocket <span class="se">\</span>
    <span class="nv">CONFIG</span><span class="o">=</span><span class="nv">$BAO_DEMOS_ROCKET_CONFIG</span>
</code></pre></div></div>

<h3 id="modifying-the-scripts">Modifying the scripts</h3>

<p>Before building the design, a few lines in the tcl scripts must be modified in order to ensure we
are building for the ZCU102. Change directory to <code class="language-plaintext highlighter-rouge">$BAO_DEMOS_VIVADO_SCRIPTS</code> and modify the switch
statement in <code class="language-plaintext highlighter-rouge">env.tcl</code> with the following information.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    zcu102 {
        set part xczu9eg-ffvb1156-2-e
        set board_part xilinx.com:zcu102:part0:3.1
    }
</code></pre></div></div>

<p>The board declaration must be changed to ZCU102 with the following line:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>set board zcu102
</code></pre></div></div>

<h3 id="building-the-soc-design">Building the SoC Design</h3>

<p>Vivado can be used with the generated verilog to build the SoC Design. Ensure that Vivado 2020.2 is
on your path and run the following commands:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vivado <span class="nt">-nolog</span> <span class="nt">-nojournal</span> <span class="nt">-mode</span> batch <span class="nt">-source</span> <span class="nv">$BAO_DEMOS_VIVADO_SCRIPTS</span>/create_ip.tcl
vivado <span class="nt">-nolog</span> <span class="nt">-nojournal</span> <span class="nt">-mode</span> batch <span class="nt">-source</span> <span class="nv">$BAO_DEMOS_VIVADO_SCRIPTS</span>/create_design.tcl
vivado <span class="nt">-nolog</span> <span class="nt">-nojournal</span> <span class="nt">-mode</span> batch <span class="nt">-source</span> <span class="nv">$BAO_DEMOS_VIVADO_SCRIPTS</span>/build.tcl
</code></pre></div></div>

<h2 id="prebuilt-rocketchip-bitstreams">Prebuilt Rocketchip Bitstreams</h2>

<p>DornerWorks has pre-built a version of the rocketchip with and without the h-extensions
available. The bitsteams, along with the corresponding <code class="language-plaintext highlighter-rouge">psu_init.tcl</code> scripts, can be found at the
following <a href="https://github.com/dornerworks/Vivado-Prebuilts">repo</a>. This repo also contains a script
to flash the rocketchip onto the ZCU102.</p>

<h2 id="booting-the-rocketchip">Booting the Rocketchip</h2>

<p>Use the Xilinx <code class="language-plaintext highlighter-rouge">xsct</code> tool to flash the ZCU102. Connect the JTAG and UART ports to your computer. If
using VMWare, ensure that USB3.0 is enabled. Set the ZCU102 to boot via JTAG and power on the board.</p>

<p>Open a <code class="language-plaintext highlighter-rouge">screen</code> session for the ZCU102 with the following command:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>screen /dev/ttyUSB1 115200
</code></pre></div></div>

<p>Next, ensure the generated seL4 image is in the binary format. This will be the case when the
<code class="language-plaintext highlighter-rouge">ElfloaderImage</code> CMake variable is set to <code class="language-plaintext highlighter-rouge">binary</code>.</p>

<p>Finally, flash the ZCU102 with the following command:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xsct  <span class="nv">$BAO_DEMOS_VIVADO_SCRIPTS</span>/deploy.tcl /PATH/TO/BINARY/SEL4/IMAGE
</code></pre></div></div>

<p>Alternatively, if using the prebuilt bitstream provided by DornerWorks, the <code class="language-plaintext highlighter-rouge">Vivado-Prebuilts</code>
repository contains a <code class="language-plaintext highlighter-rouge">flash_rocket</code> shell script which can be invoked to flash the ZCU102 with the
prebuilt bitstream.</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> <span class="nv">$DW_VIVADO_PREBUILTS</span>
<span class="nb">source </span>flash_rocket.sh /PATH/TO/BINARY/SEL4/IMAGE
</code></pre></div></div>

    </div>
  </div>
</div>

    </main>
    


<footer class="site-footer">

  <h2 class="footer-heading">seL4 docs</h2>

  <div class="footer-col-wrapper">

    <div class="col-md-2">
      



<ul class="social-media-list">
  <li><a href="https://github.com/sel4"><i class="fab fa-github"></i> <span class="username">sel4</span></a></li><li><a href="https://github.com/sel4proj"><i class="fab fa-github"></i> <span class="username">sel4proj</span></a></li>
</ul>

    </div>

    <div class="col-md-8">
      <ul class="list-unstyled">
        <li>
          This site is for displaying seL4 related documentation.  Pull requests are welcome.
        </li>
        
          <li>
            Site last updated: Fri Feb 7 10:17:38 2025 +1100 ee78c8857c
          </li>
          <li>
                Page last updated: Wed Feb 22 09:35:20 2023 +1100 517f592877
          </li>
        
      </ul>
    </div>
    <div class="col-md-2">
<a href="https://github.com/seL4/docs/blob/master/Hardware/rocketchip-zcu102.md">View page on GitHub</a>
      <br />
      <a href="https://github.com/seL4/docs/edit/master/Hardware/rocketchip-zcu102.md">Edit page on GitHub</a>
      <br />
      <a href="/sitemap">Sitemap</a>
    </div>

  </div>

</footer>

  </body>
</html>
